package com.dawn.anypossible.base.auth;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: huangxz
 * @Date: 14:24 2024-2-27
 * @Description:
 */
public class MockDbUser {

    public static Map<String, String> userPwdMap = new HashMap<>();

    private static Map<String,PasswordEncoder> encoders = new HashMap<>();

    public static PasswordEncoder passwordEncoder = null;

    static {
        encoders.put("bcrypt", new BCryptPasswordEncoder(10, new SecureRandom("neverexpose".getBytes())));
        passwordEncoder = new DelegatingPasswordEncoder("bcrypt", encoders);
        userPwdMap.put("tanxi", passwordEncoder.encode("666"));
        userPwdMap.put("admin", passwordEncoder.encode("admin"));
    }

    public static void addUser(String username,String password){
        String encode = passwordEncoder.encode(password);
        System.out.println("encode = " + encode);
        userPwdMap.put(username, encode);
    }



}
